bgp: add local_as support to BGP_NEIGHBOR template#26556
bgp: add local_as support to BGP_NEIGHBOR template#26556briantopping wants to merge 1 commit intosonic-net:masterfrom
Conversation
Add support for the local_as attribute in the BGP_NEIGHBOR CONFIG_DB table. When local_as is defined for a neighbor, the template renders: neighbor <addr> local-as <asn> no-prepend replace-as This enables operators to present a different AS number to specific peers while using a single internal AS for iBGP. Common use case: sites running iBGP internally with a private AS while presenting a public AS to upstream PE routers. Matches the local_as attribute schema used in Dell Enterprise SONiC for the BGP_NEIGHBOR and BGP_PEER_GROUP tables.
|
|
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Adds support for configuring per-neighbor BGP local-AS in the FRR bgpd neighbor instance Jinja template.
Changes:
- Conditionally renders a
neighbor <addr> local-as <asn> ...line when a local-AS attribute is present. - Leaves existing neighbor rendering (remote-as, description, timers, etc.) unchanged.
| ! | ||
| neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }} | ||
| neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }} | ||
| {% if bgp_session['local_as'] is defined %} |
There was a problem hiding this comment.
The template checks/uses bgp_session['local_as'], but the upstream CONFIG_DB/YANG schema for BGP neighbors uses local_asn (see src/sonic-yang-models/yang-models/sonic-bgp-common.yang and src/sonic-yang-models/tests/files/sample_config_db.json). As written, setting local_asn on BGP_NEIGHBOR will not render any neighbor ... local-as ... line. Consider switching to local_asn (and optionally supporting both keys for backward compatibility).
| {% if bgp_session['local_as'] is defined %} | |
| {% if bgp_session['local_asn'] is defined %} | |
| neighbor {{ neighbor_addr }} local-as {{ bgp_session['local_asn'] }} no-prepend replace-as | |
| {% elif bgp_session['local_as'] is defined %} |
| neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }} | ||
| neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }} | ||
| {% if bgp_session['local_as'] is defined %} | ||
| neighbor {{ neighbor_addr }} local-as {{ bgp_session['local_as'] }} no-prepend replace-as |
There was a problem hiding this comment.
neighbor ... local-as ... no-prepend replace-as is rendered unconditionally whenever local_as is set. CONFIG_DB/YANG also defines local_as_no_prepend and local_as_replace_as flags, and hard-coding both options changes semantics vs plain local-as for users who only want one (or neither). Consider rendering no-prepend/replace-as conditionally based on those attributes (defaulting to FRR defaults when unspecified).
| neighbor {{ neighbor_addr }} local-as {{ bgp_session['local_as'] }} no-prepend replace-as | |
| neighbor {{ neighbor_addr }} local-as {{ bgp_session['local_as'] }}{% if bgp_session['local_as_no_prepend'] is defined and bgp_session['local_as_no_prepend'] | int != 0 %} no-prepend{% endif %}{% if bgp_session['local_as_replace_as'] is defined and bgp_session['local_as_replace_as'] | int != 0 %} replace-as{% endif %} |
| {% if bgp_session['local_as'] is defined %} | ||
| neighbor {{ neighbor_addr }} local-as {{ bgp_session['local_as'] }} no-prepend replace-as |
There was a problem hiding this comment.
This new template behavior isn’t covered by existing bgpcfgd unit tests (e.g., src/sonic-bgpcfgd/tests/test_bgp.py adds peers but doesn’t assert the rendered config for new attributes). Adding a test that sets local_asn (and the optional local_as_no_prepend / local_as_replace_as flags if supported) and asserts the generated neighbor ... local-as ... line would prevent regressions.
Summary
local_asattribute support to the general BGP neighbor instance templatelocal_asis defined inBGP_NEIGHBORCONFIG_DB table, rendersneighbor <addr> local-as <asn> no-prepend replace-asin FRR configbgp_session)Motivation
Operators running iBGP internally with a private AS need to present a different (public) AS to upstream PE routers via
local-as. This is a standard BGP deployment pattern for multi-site networks.Dell Enterprise SONiC already supports the
local_asattribute inBGP_NEIGHBORandBGP_PEER_GROUPtables. This patch brings the same capability to community SONiC by adding the corresponding template logic.Example CONFIG_DB usage
Produces in FRR:
Test plan
local-aspresenting AS 10595 while router runs AS 65001local_asattribute are unaffected (conditional renders nothing)🤖 Generated with Claude Code